﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using app_common;
using System.Collections;

namespace tpos_custom_control
{
    public partial class uc_table : UserControl
    {
        private Hashtable hashBillHeader = new Hashtable();
        private bool open = false;

        public uc_table()
        {
            InitializeComponent();
        }


        private void uc_table_Resize(object sender, EventArgs e)
        {
            btn.Width = this.Width;
            btn.Height = this.Height;
        }

        public string uc_Text {
            set { btn.Text = value; }
            get { return btn.Text; }
        }

        public int uc_Height 
        {
            set { this.Height = value; btn.Height = value; }
            get { return this.Height; }
        }

        public int uc_Width
        {
            set { this.Width = value; btn.Width = value; }
            get { return this.Width; }
        }

        public bool uc_Open {
            set { this.open = value;
                    if (this.open == true)
                    {
                        uc_BackColor = Color.Red;
                    }
                    else {
                        uc_BackColor = Color.Transparent;
                    }
                }
            get { return this.open; }
        }

        public Color uc_BackColor {
            set { btn.BackColor = value; }
            get { return btn.BackColor; }
        }

        public bool uc_Enable {
            set { btn.Enabled = value; }
            get { return btn.Enabled; }
        }

        public string uc_TableCodeList {
            set {
                    if (hashBillHeader.ContainsKey("table_code_list") == true)
                    {
                        hashBillHeader["table_code_list"] = value;
                    }
                    else {
                        hashBillHeader.Add("table_code_list", value);
                    }
                }
            get {
                if (hashBillHeader.ContainsKey("table_code_list") == true)
                {
                    return hashBillHeader["table_code_list"].ToString();
                }
                else
                {
                    return "";
                }
            }
        }

        public string uc_BillCode
        {
            set
            {
                if (hashBillHeader.ContainsKey("bill_code") == true)
                {
                    hashBillHeader["bill_code"] = value;
                }
                else
                {
                    hashBillHeader.Add("bill_code", value);
                }
            }
            get
            {
                if (hashBillHeader.ContainsKey("bill_code") == true)
                {
                    return hashBillHeader["bill_code"].ToString();
                }
                else
                {
                    return "";
                }
            }
        }

        private void btn_Click(object sender, EventArgs e)
        {
            try {
                if (this.uc_Open == false)
                {
                    if (APP_DELEGATE.TABLE_CLICK != null)
                    {
                        APP_DELEGATE.TABLE_CLICK(this.Name, this.uc_Text);
                        this.uc_Enable = false;
                    }
                }
            }catch(Exception ex){
                MessageBox.Show("Xảy ra lỗi.\n\rChi tiết: " + ex.Message, STATUS_MESSAGE.CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
       }

        public void uc_Click(object sender, EventArgs e)
        {
            btn_Click(sender, e);
        }


    }
}
